package StudyCode.summary.mydatetime;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class QueryingDatetime {
	public static void main(String[] args) {
		TemporalQuery<TemporalUnit> precisionQuery = TemporalQueries.precision();
		TemporalQuery<LocalDate> localDateQuery = TemporalQueries.localDate();

		// 查询 LocalDate
		LocalDate ld = LocalDate.now();
		TemporalUnit precision = ld.query(precisionQuery);
		LocalDate queryDate = ld.query(localDateQuery);
		System.out.println("时间精度 LocalDate: " + precision);
		System.out.println("时间日期 LocalDate: " + queryDate);

		// 查询 LocalTime
		LocalTime lt = LocalTime.now();
		precision = lt.query(precisionQuery);
		queryDate = lt.query(localDateQuery);
		System.out.println("时间精度 LocalTime: " + precision);
		System.out.println("时间日期 LocalTime: " + queryDate);

		// 查询 ZonedDateTime
		ZonedDateTime zdt = ZonedDateTime.now();
		precision = zdt.query(precisionQuery);
		queryDate = zdt.query(localDateQuery);
		System.out.println("时间精度 ZonedDateTime: " + precision);
		System.out.println("时间日期 ZonedDateTime: " + queryDate);
	}
}
